package com.waitingsnow.modules.giftPlay.model
{
import com.waitingsnow.core.debug.Logger;
import com.waitingsnow.core.model.config.AppConfig;
import com.waitingsnow.core.model.vo.GiftVO;
import com.waitingsnow.core.util.ds.ExternalUtil;
import com.waitingsnow.modules.giftPlay.model.events.GiftPlayProxyEvent;

import flash.events.EventDispatcher;

/**
 * 
 * @author waitingsnow
 * $Id: GiftPlayProxy.as 2 2012-05-17 10:10:03Z cgslendy@gmail.com $
 */
public class GiftPlayProxy extends EventDispatcher
{
	//==========================================================================
	//  Class variables
	//==========================================================================
	static public const NAME:String = "GiftPlayProxy";
	
	//==========================================================================
	//  Constructor
	//==========================================================================
	/**
	 * Constructs a new <code>GiftPlayProxy</code> instance.
	 * 
	 */
	public function GiftPlayProxy()
	{
	}
	
	//==========================================================================
	//  Variables
	//==========================================================================
	private var giftArr:Array = [];
	
	//==========================================================================
	//  Properties
	//==========================================================================
	private var _playGiftArr:Array = [];
	public function get playGiftArr():Array
	{
		return _playGiftArr;
	}
	
	//==========================================================================
	//  Methods
	//==========================================================================
	public function getGiftData():void
	{
		var arr:Array = ExternalUtil.call(AppConfig.GET_GIFTS_TO_JS);
		
		/*arr = [{id:2, name:"红玫瑰", info:"test", icon_path:"/gifts/3.png", sort_num:1, 
			price:2, play_type:1, gift_type:1, swf_path:"/gifts/2.swf"},
			{id:3, name:"红玫瑰", info:"test", icon_path:"/gifts/3.png", sort_num:1, 
				price:2, play_type:1, gift_type:1, swf_path:"/gifts/3.swf"},
			{id:4, name:"红玫瑰", info:"test", icon_path:"/gifts/3.png", sort_num:1, 
				price:2, play_type:1, gift_type:1, swf_path:"/gifts/4.swf"},
			{id:5, name:"红玫瑰", info:"test", icon_path:"/gifts/3.png", sort_num:1, 
				price:2, play_type:1, gift_type:1, swf_path:"/gifts/5.swf"},
			{id:1, name:"红玫瑰", info:"test", icon_path:"/gifts/3.png", sort_num:1, 
				price:2, play_type:2, gift_type:2, swf_path:"/gifts/1.swf"}];*/
		Logger.logArray("获得礼物数组： ", arr);
		
		//get Gifts
		var giftVO:GiftVO;
		for each(var obj:Object in arr)
		{
			giftVO = new GiftVO();
			giftVO.giftID = obj.id;
			giftVO.giftName = obj.name;
			giftVO.giftInfo = obj.info;
			giftVO.iconPath = ExternalVars.getVersionUrl(obj.icon_path);
			giftVO.sortNum = obj.sort_num;
			giftVO.giftPrice = obj.price;
			giftVO.playType = obj.play_type;
			giftVO.giftType = obj.gift_type;
			giftVO.swfPath = ExternalVars.getVersionUrl(obj.swf_path);
			giftArr.push(giftVO);
		}
		dispatchEvent(new GiftPlayProxyEvent(GiftPlayProxyEvent.GET_GIFT_PLAY));
	}
	
	public function getGiftVOByID(giftID:int):GiftVO
	{
		var giftVO:GiftVO;
		for each (giftVO in giftArr)
		{
			if (giftVO.giftID == giftID)
			{
				break;
			}
		}
		return giftVO;
	}
	
	public function pushGift(giftVO:GiftVO):void
	{
		_playGiftArr.push(giftVO);
	}
	
	public function getCurGift():GiftVO
	{
		var giftVO:GiftVO = _playGiftArr.shift();
		return giftVO;
	}
}
}